package bean.admin.login;

import com.alibaba.fastjson.JSON;
import util.JDBCConnection;

import java.sql.ResultSet;
import java.util.Date;

public class AdminLoginBean {
    int code;
    String message;
    String token;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String admin_login(String admin_id,String admin_pwd){
        JDBCConnection jdbc = new JDBCConnection();
        code = 0;
        message = "成功";
        String querySQL = "select adminpsd from lotmanager where adminid = \""+admin_id+"\"";
        ResultSet rs = jdbc.executeQuery(querySQL);
        try {
            rs.next();
            if(rs.getString("adminpsd")==null){
                message="登录账户不存在";
            }
            else if(rs.getString("adminpsd").equals(admin_pwd)){
                message="登录成功";
                Date date = new Date();
                //后面直接查看账号密码  及其不安全
                token = admin_id+"#"+date.getTime()+"#"+admin_pwd;
            }
            else{
                message="密码错误";
            }
        }catch (Exception e){
            message=e.toString();
            code = 100;
        }
        return JSON.toJSONString(this);
}
}
